﻿using System;
using System.Collections;
using System.Data;
using System.Web;
using System.Web.UI.HtmlControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using AnyOffice.Model;
using AnyOffice.WorkFlowRegex;
using PickListControl;
using System.Web.UI.WebControls;
namespace AnyOffice.general.system.workflow.flow_type
{   
    public partial class type_process_item : ModulePage
    {      
        private int flowid;
        private int _id;
        private string prcsItem = "";       

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                ListItem item;
                this.flowid = (Request.QueryString["flow_id"] == null) ? 0 : int.Parse(Request.QueryString["flow_id"].ToString());
                this.ViewState["FlowId"] = this.flowid;
                bool flag = Request.QueryString["graph"] != null;
                this.ViewState["IsGraph"] = flag;
                if (flag)
                {
                    this.litButton.Text = "<input type=\"button\" value=\"关闭\" class=\"BigButton\" name=\"back\" onClick=\"window.close();\">";
                }
                else
                {
                    this.litButton.Text = "<input type=\"button\" value=\"返回\" class=\"BigButton\" name=\"back\" onClick=\"history.back();\">";
                }
                this._id = (Request.QueryString["id"] == null) ? 0 : int.Parse(Request.QueryString["id"].ToString());
                this.ViewState["Id"] = this._id;
                DataTable table = new FlowFormTypeDao().SelectByFlowId(base.Conn, this.flowid);
                FormRegex regex = new FormRegex();
                if (table.Rows.Count > 0)
                {
                    regex.HtmlSource = (table.Rows[0]["FormModel"] != DBNull.Value) ? table.Rows[0]["FormModel"].ToString() : "";
                }
                ArrayList titleValue = regex.GetTitleValue();
                DataTable table2 = new FlowProcessDao().SelectById(base.Conn, this._id);
                if (table2.Rows.Count > 0)
                {
                    this.litPrcsId.Text = table2.Rows[0]["PrcsId"].ToString();
                    this.prcsItem = (table2.Rows[0]["PrcsItem"] != DBNull.Value) ? table2.Rows[0]["PrcsItem"].ToString() : "";
                    this.prcsItem = "," + this.prcsItem + ",";
                }
                for (int i = 0; i < titleValue.Count; i++)
                {
                    item = new ListItem(titleValue[i].ToString(), titleValue[i].ToString());
                    if (this.prcsItem.IndexOf("," + titleValue[i].ToString() + ",") >= 0)
                    {
                        this.pklPrcsItem.ItemsLeft.Add(item);
                    }
                    else
                    {
                        this.pklPrcsItem.ItemsRight.Add(item);
                    }
                }
                item = new ListItem("[流程公共附件]", "[A@]");
                if (this.prcsItem.IndexOf(",[A@],") >= 0)
                {
                    this.pklPrcsItem.ItemsLeft.Add(item);
                }
                else
                {
                    this.pklPrcsItem.ItemsRight.Add(item);
                }
                item = new ListItem("[工作名称/文号]", "[B@]");
                if (this.prcsItem.IndexOf(",[B@],") >= 0)
                {
                    this.pklPrcsItem.ItemsLeft.Add(item);
                }
                else
                {
                    this.pklPrcsItem.ItemsRight.Add(item);
                }
            }
            if (this.Page.IsPostBack)
            {
                this._id = Convert.ToInt32(this.ViewState["Id"]);
                foreach (ListItem item2 in this.pklPrcsItem.ItemsLeft)
                {
                    this.prcsItem = this.prcsItem + item2.Value + ",";
                }
                FlowProcessDao dao3 = new FlowProcessDao();
                FlowProcessData olll = new FlowProcessData();
                olll.Id = this._id;
                olll.PrcsItem = this.prcsItem;
                dao3.SetPrcsItem(base.Conn, olll);
                base.CloseConn();
                if (Convert.ToBoolean(this.ViewState["IsGraph"].ToString()))
                {
                    if (!this.Page.IsStartupScriptRegistered("SefClose"))
                    {
                        this.Page.RegisterStartupScript("SefClose", "<script>parent.opener.location.reload();\nwindow.close();</script>\n");
                    }
                }
                else
                {
                    Response.Redirect("type_view_list.aspx?flow_id=" + this.ViewState["FlowId"].ToString());
                }
            }
        }
      
    }
}

